// pages/checkJoin/checkJoin.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showAuthList: false,
    showchoose:false,
    authList: [],
    orgPositions:'',
    status:null,
    param: {

    },
    detail: {},
    columns: [],
    column:[]
  },
  preventTouchMove: function (e) {
  },
  call(e) {
    var dataset = e.currentTarget.dataset;
    wx.makePhoneCall({
      phoneNumber: dataset.tel
    })
  },
  onConfirm(event) {
    const {
      picker,
      value,
      index
    } = event.detail;
    Toast(`当前值：${value}, 当前索引：${index}`);
  },
  onCancel() {
    Toast('取消');
  },
  toggle(type, val) {
    this.setData({
      [type]: val
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.toggle("param.orgId", options.orgId);
    this.toggle("param.listId", options.id);
    this.toggle("param.viewUid", options.userId);
  },
  refreshDetail: function() {
    var that = this;;
    app.getUserInfo(function(userInfo) {
      that.toggle("param.uid", userInfo.id);
      that.detail();
    });
  },
  detail: function() {
    var that = this;
    var param = that.data.param;
    var data={};
    app.req({
      url: "orgmini/manager/audit/getOrgMembershipDetails",
      data: param,
      success: function(res) {
        if (200 == res.code) {
          var detail = res.data;
          var data = detail.programUserEntity;
          data.orgReviewStatus = detail.orgReviewStatus;
          var orgList = [];
          if (detail.userOrgList) {
            for (let i of detail.userOrgList) {
              if (!!i.isBusinessCard) {
                orgList.push(i);
              }
            }
          }
          data.orgList = orgList;
          wx.setNavigationBarTitle({
            title: data.realName + "的名片"
          })
          that.toggle("detail", data);
        }
      }
    });
  },
  noPass: function() {
    var that = this
    that.toggle("status", 2);
    wx.showModal({
      title: '提示',
      content: '是否确认拒绝审核？',
      cancelColor:'#999999',
      confirmText:'确认',
      confirmColor:'#2168EB',
      success(res) {
        if (res.confirm) {
          that.operation();
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
    
  },
  onAuthClose: function() {
    this.toggle("showAuthList", false);
    this.toggle("authList", []);
    this.toggle("columns", []);
  },
  onAuthSelect: function(e) {
    var that = this;
    var i = e.detail.index
    var id = that.data.authList[i].id
    that.operation(1, id);
    that.toggle("showAuthList", false);
  },
  pass: function() {
    // this.toggle("authList", []);
    this.toggle("columns", []);
    this.toggle("showchoose", true);
    this.toggle("status", 1);
    var that = this;
    app.req({
      // url: "orgmini/org/getOrgStructure",
      url: "orgmini/org/newOrgStructure",
      data: {
        orgId: that.data.param.orgId
      },
      success: function(res) {
        if (200 == res.code) {
          // var authList = [];
          var columns = [];
          // columns = res.data.orgStructureListDtos
          for (var i in res.data.orgStructureListDtos) {
            res.data.orgStructureListDtos[i].isAdmin = 0
          }
          // for (var i of res.data.orgStructureListDtos) {
          //   res.data.orgStructureListDtos[i].flag=0
          //   authList.push({
          //     name: i.structure,
          //     id: i.id
          //   });
          //   columns.push(i.structure);
          // }
          that.toggle("columns", res.data.orgStructureListDtos);
          // that.toggle("authList", authList);
          // that.toggle("showAuthList", true);
        }
      }
    });
  },
  orgPositionsIpt(e){
    this.toggle('orgPositions', e.detail.value)
  },
  choiceBm(){
    this.setData({
      showAuthList: true
    })
  },
  choosebtn(e){
    var i =e.currentTarget.dataset.index
    var arr = this.data.columns
    if (arr[i].isAdmin==1){
      arr[i].isAdmin=0
    }else{
      arr[i].isAdmin = 1
    }
    this.toggle("columns", arr);
  },
  bmconfirmbtn(){
    var arry=[]
    for (var j in this.data.columns){
      if (this.data.columns[j].isAdmin==1){
        arry.push(this.data.columns[j])
      }
    }
    this.setData({
      showAuthList:false,
      column:arry
    })
  },
  hideshow(){
    this.setData({
      showAuthList: false,
      columns:[]
    })
  },
  operation: function() {
    var that = this;
    var structureList = [];
    if (that.data.column.length>0){
      for (var i in that.data.column) {
        structureList.push(that.data.column[i].id)
      }
    }
    var param = that.data.param;
    var data = {};
    data.orgId = param.orgId;
    data.userId = param.viewUid;
    data.viewUid = param.viewUid;
    data.id = param.listId;
    data.listId = param.listId;
    data.status = that.data.status
    data.structureList = structureList
    data.orgPositions =that.data.orgPositions
    // data.identityAuth = authId || '';
    app.req({
      url: "orgmini/org/newOrgCheckMembership?",
      data: data,
      success: function(res) {
        if (200 == res.code) {
          wx.navigateBack();
        }
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.refreshDetail();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.refreshDetail();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})